package com.example.yrdev.ordering_system.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.example.yrdev.ordering_system.Model.Operator;
import com.example.yrdev.ordering_system.R;
import com.example.yrdev.ordering_system.Utils.GlobalFunction;

import org.androidannotations.annotations.WindowFeature;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by luke on 12/11/16.
 */

public class InputPassDialog extends Dialog {
   public interface  Callback{

     void grantAccess();

    }
  private   Callback callback;
    private  Context context;
    public void setCallback(Callback callback) {
        this.callback = callback;

    }

    @InjectView(R.id.pass)EditText pass;

    public InputPassDialog(Context context){
        super(context);
        this.context=context;
        requestWindowFeature(Window.FEATURE_NO_TITLE);


    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.input_pass_dialog);
        ButterKnife.inject(this);
        getWindow().setLayout(  WindowManager.LayoutParams.MATCH_PARENT,   WindowManager.LayoutParams.WRAP_CONTENT);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);//直接弹出输入框\
        getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    }
    @OnClick(R.id.confirm)
    void confPass(){

        if (pass.getText().length()<=0){

            GlobalFunction.ToastAlert(context,"请输入密码");

        }else {

            if (pass.getText().toString().equals(Operator.getIntance().getPassword())){

                if (this.callback!=null)
                    this.callback.grantAccess();

            }else {

                GlobalFunction.ToastAlert(context,"非常抱歉，密码有误");

            }

        }
    }
}
